from collections import Counter

from sklearn.datasets import load_iris
from sklearn.model_selection import KFold
from sklearn.model_selection import StratifiedKFold


def test01():
    # 加载数据
    x, y = load_iris(return_X_y=True)
    print('随机类别划分：', Counter(y))
    #随机交叉验证
    splitter = KFold(n_splits=5, shuffle=True, random_state=0)
    for train, test in splitter.split(x, y):
        print('随机分割:', Counter(y[test]))
    #分层交叉验证
    splitter = StratifiedKFold(n_splits=5, shuffle=True, random_state=0)
    for train, test in splitter.split(x, y):
        print('分层分割:', Counter(y[test]))

if __name__ == '__main__':
    test01()